package com.app.common.net

import org.json.JSONObject


/**
 * 通用请求返回数据
 */
data class BaseApiResult<T>(
    val resultCode: Int = -1,
    val status: String = "",
    val errorMsg: String = "",
    val data: T
) {
    var body = ""

    val success
        get() = resultCode == 0
}

/**
 * JL通用返回数据
 */
data class Response(
    val code: Int = -1,
    val errorMsg: String = "",
    val errorMsgTrnId: Int = -1,
    val attrs: JSONObject? = null
) {
    var body = ""
    val success
        get() = code == 0

    fun attr(key: String): String {
        return attrs?.optString(key) ?: ""
    }

    fun attrInt(key: String): Int {
        return attrs?.optInt(key, -1) ?: -1
    }
}